<template>
	<view>
		<button class="btn"  @tap="getpay">确认支付</button>
	</view>
</template>

<script>
	import { mapState, mapGetters, mapMutation, mapActions } from 'vuex';
	export default {
		computed: {
			...mapState({
				openid: state => state.user.openid
			})
		},
		data() {
			return {
				
			}
		},
		methods: {				
			getpay(){ //获取微信支付签名
				this.$store
					.dispatch('getpay',{
						openid:this.openid						
					})
					.then(res => {
						this.payOrder(res.data)
					});
			},
			payOrder(res) {
					//微信支付接口
					wx.requestPayment({
						timeStamp: res.timeStamp,
						nonceStr: res.nonceStr,
						package: res.package,
						signType: res.signType,
						paySign: res.paySign,
						success: res => {							
							uni.redirectTo({
								url:"../login/login"								
							});							
						},
						fail: res => {
							if(res.errMsg == "requestPayment:fail cancel"){
								uni.showToast({
									title: '您取消了支付',
									icon: "none"
								})
							}else {
								uni.showToast({
									title: '支付失败，请稍后再试',
									icon: "none"
								})
							}
							
						},
						complete: res => {}
					});
				
			}
		}
	}
</script>

<style lang="less">
.btn{
	height: 80rpx;
	color: #fff;
	background-color: #0077AA;
	font-size: 30rpx;
}
</style>
